package fem2.jlinalg;

import fem2.Debugger;
import inf.jlinalg.Array2DMatrix;
import inf.jlinalg.ArrayVector;
import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;
import math2.LinAlgUtilities;

import org.junit.Test;

public class EigenvalueDecompositionTest {

	@Test
	public void test1() {
		double[][] A = new double[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
		EigenvalueDecomposition eig = new EigenvalueDecomposition(new Array2DMatrix(A));

		Debugger.watch(eig.getD());
		Debugger.watch(eig.getV());
	}

	@Test
	public void test2() {
		double[][] A = new double[][] { { 0.8147, 0.0975, 0.1576, 0.1419, 0.6557 },
				{ 0.9058, 0.2785, 0.9706, 0.4218, 0.0357 },
				{ 0.1270, 0.5469, 0.9572, 0.9157, 0.8491 },
				{ 0.9134, 0.9575, 0.4854, 0.7922, 0.9340 },
				{ 0.6324, 0.9649, 0.8003, 0.9595, 0.6787 }

		};
		EigenvalueDecomposition eig = new EigenvalueDecomposition(new Array2DMatrix(A));

		Debugger.watch(eig.getD()); // correct in matlab
		Debugger.watch(eig.getV());
	}

	@Test
	public void test3() {
		IVector s = new ArrayVector(1, 2, 3, 0, 0, 0);
		IVector ps = new ArrayVector(3);
		IMatrix pd = new Array2DMatrix(3, 3);
		LinAlgUtilities.decomposePrincipalStress(3, s, ps, pd);
		Debugger.watch(ps); // correct
		Debugger.watch(pd); // correct
	}

	@Test
	public void test4() {
		IVector s = new ArrayVector(1, 2, 3, 0.1, 0.2, 0.3);
		IVector ps = new ArrayVector(3);
		IMatrix pd = new Array2DMatrix(3, 3);
		LinAlgUtilities.decomposePrincipalStress(3, s, ps, pd);
		Debugger.watch(ps); // correct
		Debugger.watch(pd); // correct
	}

	@Test
	public void test5() {
		IVector s = new ArrayVector(2, 3, 1, 0.1, 0.2, 0.3);
		IVector ps = new ArrayVector(3);
		IMatrix pd = new Array2DMatrix(3, 3);
		LinAlgUtilities.decomposePrincipalStress(3, s, ps, pd);
		Debugger.watch(ps); // correct
		Debugger.watch(pd); // correct
	}

	@Test
	public void test6() {
		double[][] A = new double[][] { { 0.9999999999999999, 0, -2.135044278125301E-17 },
				{ 0, -1.1102230246251565E-16, 0 }, { -2.135044278125301E-17, 0, 0 } };
		EigenvalueDecomposition eig = new EigenvalueDecomposition(new Array2DMatrix(A));

		Debugger.watch(eig.getD());
		Debugger.watch(eig.getV());
	}

	@Test
	public void test7() {
		IVector s = new ArrayVector(0.9999999999999999, -1.1102230246251565E-16, 0, 0, 0,
				-2.135044278125301E-17);
		IVector ps = new ArrayVector(3);
		IMatrix pd = new Array2DMatrix(3, 3);

		LinAlgUtilities.decomposePrincipalStress(3, s, ps, pd);

		Debugger.watch(ps);
		Debugger.watch(pd);
	}

}
